package visao.turma;

import javax.swing.JDialog;
import javax.swing.JFrame;

import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import modelagem.Turma;

import com.towel.el.annotation.AnnotationResolver;
import com.towel.swing.table.ObjectTableModel;

import controle.turma.acoesBuscadeTurma;
import controle.turma.turmaDAO;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class BuscadeTurma extends JDialog {
	private interfaceTurma it;
	private JButton btnSair;
	private ObjectTableModel<Turma> modeloTabela;
	private JTable table;
	
	public BuscadeTurma() {
		this.setBounds(100, 100, 505, 400);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		this.setModal(true);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		getContentPane().setLayout(new BorderLayout(0, 0));
		
		JPanel panelPrincipal = new JPanel();
		getContentPane().add(panelPrincipal, BorderLayout.CENTER);
		panelPrincipal.setLayout(new BorderLayout(0, 0));
		
		modeloTabela = new ObjectTableModel<Turma>(new AnnotationResolver(Turma.class), "codigo,profNome,cursoNome");
		modeloTabela.addAll(new turmaDAO().buscar());
		
		table = new JTable(modeloTabela);
		panelPrincipal.add(table, BorderLayout.NORTH);
		
		JScrollPane scrollPane = new JScrollPane(table);
		panelPrincipal.add(scrollPane);
		
		JPanel PainelBotoes = new JPanel();
		getContentPane().add(PainelBotoes, BorderLayout.SOUTH);
		
		btnSair = new JButton("Sair");
		btnSair.addActionListener(new acoesBuscadeTurma(this));
		btnSair.setName("Sair");
		PainelBotoes.add(btnSair);
	}
	
	public BuscadeTurma(interfaceTurma it){
		this();
		this.it = it;
	}

	public JButton getBtnSair() {
		return btnSair;
	}

	public ObjectTableModel<Turma> getModeloTabela() {
		return modeloTabela;
	}

	public JTable getTable() {
		return table;
	}
}
